home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBVGAL17.ARJ / DEMOS.ARJ / TESTVL.C < prev    next >
C/C++ Source or Header  |  1992-01-26  |  13KB  |  476 lines

  1. #define _MAIN_
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7. #include <mem.h>
  8. #include "vidlib.h"
  9. #include "vesa.h"
  10.  
  11. char teststring1[]= "0123456789abcdefghijklmnopqrstuvwxyz├";
  12. char teststring2[]= "─┼┤ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  13.  
  14. char temps[100];
  15. char newpalette[768];
  16. char * capture;
  17.  
  18. void pause(void);
  19. void palette_check(void);
  20. void Make_newpalette(void);
  21. void Test_textmode(void);
  22. void Test_modex10(void);
  23. void Test_modex12(void);
  24. void Test_modex13(void);
  25. void Test_vesax100(void);
  26. void Test_palettes(void);
  27.  
  28. void main(int argc, char *argv[])
  29. {
  30.   int choice=-1;
  31.  
  32.   printf("VIDLIB v%s Testvl (Test video lib).\n",
  33.                   VIDLIB_VERSION);
  34.   if ( ! isVGA() ) {
  35.       printf("\nSorry, you need to have a VGA video board to run this.\n");
  36.       exit(1);
  37.   }
  38.   if ( (capture=(char *)malloc(6400)) == NULL) {
  39.       printf("Malloc failed.\n");
  40.       exit(1);
  41.   }
  42.  
  43.   if (argc > 1) {
  44.       if ( argv[1][0]== '-' ) {
  45.          Start_vgadebug("testvl.dbg");
  46.          sprintf(tdbg,"capture=%Fp\n", capture);
  47.          fputs(tdbg,vgadebug);
  48.       }
  49.   }
  50.  
  51.   Vinit();
  52.   /* start */
  53.   while ( choice != 0 ) {
  54.     Textmode(25);
  55.     printf("VIDLIB v%s Testvl (Test video lib).\n",
  56.                   VIDLIB_VERSION);
  57.     printf("\n\n     Enter your choice of tests:\n\n");
  58.     printf(    "     0 - Exit\n");
  59.     printf(    "     1 - Text modes (25, 28, 33, 40, and 50 line modes)\n");
  60.     printf(    "     2 - EGA mode 0x10 (640x350 16 colors)\n");
  61.     printf(    "     3 - VGA mode 0x12 (640x480 16 colors)\n");
  62.     printf(    "     4 - VGA mode 0x13 (320x200 256 colors)\n");
  63.     printf(    "     5 - VESA mode 0x100 (640x400 256 colors)\n");
  64.     printf(    "     6 - Mode 0x13 palettes\n");
  65.     choice=getch()-'0';
  66.     switch (choice) {
  67.       case 0 : break;
  68.       case 1 : Test_textmode();
  69.                break;
  70.       case 2 : Test_modex10();
  71.                break;
  72.       case 3 : Test_modex12();
  73.                break;
  74.       case 4 : Test_modex13();
  75.                break;
  76.       case 5 : Test_vesax100();
  77.                break;
  78.       case 6 : Test_palettes();
  79.                break;
  80.     }
  81.   }
  82.  
  83.   /**************************************/
  84.   /* Exit                               */
  85.   /**************************************/
  86.   if (vgadebug) Close_vgadebug();
  87.   Vclose();
  88.   exit(0);
  89. }
  90. /****************************** E n d  M a i n ******************************/
  91.  
  92. /**************************************/
  93. /* 640x350  functions                 */
  94. /**************************************/
  95. void Test_modex10(void)
  96. {
  97.    int rc, i;
  98.  
  99.    rc=VGAmode(0x10, NULL);
  100.    sprintf(temps,"VGAmode 0x10: 25 lines (hit any key to continue)"
  101.                  "\r\n", rc);
  102.    _foreground_color=0x21;
  103.    Vputs(temps);
  104.    _foreground_color=0x22;
  105.    for (i=2; i<16; i++) {
  106.        sprintf(temps,"%2u %s%s\r\n", i, teststring1, teststring2);
  107.        Vputs(temps);
  108.    }
  109.    pause();
  110.    _foreground_color=0x23;
  111.    Vputs(
  112.      "Testing Vdisable_refresh (will blank the screen until you hit a key)");
  113.    pause();
  114.    Vdisable_refresh();
  115.    pause();
  116.    Venable_refresh();
  117.    _foreground_color=0x24;
  118.    Vputs("\r\n...tested Venable_refresh\r\n");
  119.    pause();
  120.    _foreground_color=0x25;
  121.    Vputs("Doing Vcopy16(0, 350, 0, 0, 40, 175).(off-screen)\r\n");
  122.    pause();
  123.    rc=Vcopy16(0, 350, 0, 0, 40, 175);
  124.    pause();
  125.    sprintf(temps,"Vcopy16(...)=%u\r\n", rc);
  126.    _foreground_color=0x26;
  127.    Vputs(temps);
  128.    pause();
  129.    _foreground_color=0x27;
  130.    Vputs("Doing Vcopy16(30, 171, 0, 350, 40, 175).\r\n");
  131.    pause();
  132.    rc=Vcopy16(30, 171, 0, 350, 40, 175);
  133.    pause();
  134.    sprintf(temps,"Vcopy16(...)=%u\r\n", rc);
  135.    _foreground_color=0x28;
  136.    Vputs(temps);
  137.    pause();
  138.    _foreground_color=0x29;
  139.    Vputs("Doing Vcapt16(&capture, 20, 80, 0, 0, 11, 3, 20, 80).\r\n");
  140.    pause();
  141.    rc=Vcapt16(capture, 20, 80, 0, 0, 11, 3, 20, 80);
  142.    pause();
  143.    sprintf(temps,"Vcapt16(...)=%u\r\n", rc);
  144.    _foreground_color=0x2a;
  145.    Vputs(temps);
  146.    pause();
  147.    _foreground_color=0x2b;
  148.    Vputs("Doing Vdisp16(10, 76, &capture, 20, 80, 0, 0, 20, 80).\r\n");
  149.    pause();
  150.    rc=Vdisp16(15, 26, capture, 20, 80, 0, 0, 20, 80);
  151.    pause();
  152.    sprintf(temps,"Vdisp16(...)=%u\r\n", rc);
  153.    _foreground_color=0x2c;
  154.    Vputs(temps);
  155.    pause();
  156. }
  157.  
  158. /**************************************/
  159. /* 640x480  functions                 */
  160. /**************************************/
  161. void Test_modex12(void)
  162. {
  163.    int rc, i;
  164.  
  165.    rc=VGAmode(0x12,NULL);
  166.    sprintf(temps,"VGAmode 0x12: 30 lines (hit any key to continue)"
  167.                  "\r\n", rc);
  168.    _foreground_color=0x32;
  169.    Vputs(temps);
  170.    _foreground_color=0x33;
  171.    for (i=2; i<22; i++) {
  172.        sprintf(temps,"%2u %s%s\r\n", i, teststring1, teststring2);
  173.        Vputs(temps);
  174.    }
  175.    pause();
  176.    _foreground_color=0x34;
  177.    Vputs("Doing Vcopy16(0, 480, 0, 0, 40, 240).(off-screen)\r\n");
  178.    pause();
  179.    rc=Vcopy16(0, 480, 0, 0, 40, 240);
  180.    pause();
  181.    sprintf(temps,"Vcopy16(...)=%u\r\n", rc);
  182.    _foreground_color=0x35;
  183.    Vputs(temps);
  184.    pause();
  185.    _foreground_color=0x37;
  186.    Vputs("Doing Vcopy16(30, 201, 0, 480, 40, 240).\r\n");
  187.    pause();
  188.    rc=Vcopy16(30, 201, 0, 480, 40, 240);
  189.    pause();
  190.    sprintf(temps,"Vcopy16(...)=%u\r\n", rc);
  191.    _foreground_color=0x38;
  192.    Vputs(temps);
  193.    pause();
  194.  
  195.    _foreground_color=0x39;
  196.    Vputs("Doing Vcapt16(&capture, 20, 80, 0, 0, 0, 0, 20, 80).\r\n");
  197.    pause();
  198.    rc=Vcapt16(capture, 20, 80, 0, 0, 0, 0, 20, 80);
  199.    pause();
  200.    sprintf(temps,"Vcapt16(...)=%u\r\n", rc);
  201.    _foreground_color=0x3a;
  202.    Vputs(temps);
  203.    pause();
  204.    _foreground_color=0x3b;
  205.    Vputs("Doing Vdisp16(10, 76, &capture, 20, 80, 0, 0, 20, 80).\r\n");
  206.    pause();
  207.    rc=Vdisp16(15, 26, capture, 20, 80, 0, 0, 20, 80);
  208.    pause();
  209.    sprintf(temps,"Vdisp16(...)=%u\r\n", rc);
  210.    _foreground_color=0x3c;
  211.    Vputs(temps);
  212.    pause();
  213. }
  214.  
  215. /**************************************/
  216. /* 320x200  functions                 */
  217. /**************************************/
  218. void Test_modex13(void)
  219. {
  220.    int rc, i;
  221.  
  222.   rc=VGAmode(0x13,NULL);
  223.   sprintf(temps,"VGAmode 0x13: 40 x 25 lines"
  224.                 "  (hit any key to continue)\r\n", rc);
  225.   _foreground_color=0x44;
  226.   Vputs(temps);
  227.   _foreground_color++;
  228.   for (i=3; i<19; i++) {
  229.        sprintf(temps,"%2u %s\r\n", i, teststring1+1);
  230.        Vputs(temps); _foreground_color++;
  231.   }
  232.   pause();
  233.   _foreground_color=0x15;
  234.   Vputs("Doing Vcopy256(...).\r\n");
  235.   pause();
  236.   rc=Vcopy256(160, 100, 0, 0, 160, 100);
  237.   pause();
  238.   sprintf(temps,"Vcopy256(...)=%u\r\n", rc);
  239.   _foreground_color++;
  240.   Vputs(temps);
  241.   pause();
  242.  
  243.   _foreground_color++;
  244.   Vputs("Doing Vcapt256(...).\r\n");
  245.   pause();
  246.   rc=Vcapt256(capture, 80, 80, 0, 0, 0, 0, 80, 80);
  247.   pause();
  248.   sprintf(temps,"Vcapt256(...)=%u\r\n", rc);
  249.   _foreground_color++;
  250.   Vputs(temps);
  251.   pause();
  252.  
  253.   _foreground_color++;
  254.   Vputs("Doing Vdisp256(...).\r\n");
  255.   pause();
  256.   rc=Vdisp256(44, 44, capture, 80, 80, 0, 0, 80, 80);
  257.   pause();
  258.   sprintf(temps,"Vdisp256(...)=%u\r\n", rc);
  259.   _foreground_color++;
  260.   Vputs(temps);
  261.   pause();
  262. }
  263.  
  264. void Test_palettes(void)
  265. {
  266.   printf("\n\n");
  267.   printf("DEFAULTDAC : the dac register contents when Vinit() was run.\n");
  268.   printf("NULL       : the dac register contents after the last mode change.\n");
  269.   printf("newpalette : an example palette created by this program.\n");
  270.   printf("\n(Hit a key)\n");
  271.   pause();
  272.   printf("Doing palette_check() with 'DEFAULTDAC'\n");
  273.   pause();
  274.   VGAmode(0x13,DEFAULTDAC);
  275.   palette_check();
  276.   pause();
  277.   Vputs("Doing palette_check() with 'NULL'\r\n");
  278.   pause();
  279.   VGAmode(0x13,NULL);
  280.   palette_check();
  281.   pause();
  282.   Make_newpalette();
  283.   Vputs("Doing palette_check() with 'newpalette'\r\n");
  284.   pause();
  285.   VGAmode(0x13,newpalette);
  286.   palette_check();
  287.   pause();
  288. }
  289.  
  290. void pause(void)
  291. {
  292.    int t;
  293.    t=getch();
  294.    if ( t == 27 ) {
  295.       if (vgadebug) Close_vgadebug();
  296.       Vclose();
  297.       exit(0);
  298.    }
  299. }
  300.  
  301. void palette_check(void)
  302. {
  303.    int i,j,c;
  304.    Vfill256(0,0,320,200,0); /* clear screen */
  305.    for (i=c=0; i<16; i++) {
  306.        for (j=0; j<16; j++) {
  307.            Vfill256(j*20,i*11+13,19,10,c);
  308.            c++;
  309.        }
  310.    }
  311. }
  312.  
  313. void Make_newpalette(void)
  314. {
  315.    int i;
  316.    char *np;
  317.  
  318.    np=newpalette;
  319.    memcpy(np,_olddacs,96); /* 32 entries */
  320.    for (i=32; i<64; i++) {
  321.       *(np+i*3)=i*2;
  322.       *(np+i*3+1)=i*2;
  323.       *(np+i*3+2)=i*2;
  324.    }
  325.    for (i=64; i<96; i++) {
  326.       *(np+i*3)=i*2;
  327.       *(np+i*3+1)=0;
  328.       *(np+i*3+2)=0;
  329.    }
  330.    for (i=96; i<128; i++) {
  331.       *(np+i*3)=0;
  332.       *(np+i*3+1)=i*2;
  333.       *(np+i*3+2)=0;
  334.    }
  335.    for (i=128; i<160; i++) {
  336.       *(np+i*3)=0;
  337.       *(np+i*3+1)=0;
  338.       *(np+i*3+2)=i*2;
  339.    }
  340.    for (i=160; i<192; i++) {
  341.       *(np+i*3)=i*2;
  342.       *(np+i*3+1)=i*2;
  343.       *(np+i*3+2)=0;
  344.    }
  345.    for (i=192; i<224; i++) {
  346.       *(np+i*3)=i*2;
  347.       *(np+i*3+1)=0;
  348.       *(np+i*3+2)=i*2;
  349.    }
  350.    for (i=224; i<256; i++) {
  351.       *(np+i*3)=0;
  352.       *(np+i*3+1)=i*2;
  353.       *(np+i*3+2)=i*2;
  354.    }
  355. }
  356.  
  357. /**************************************/
  358. /* Textmode functions                 */
  359. /**************************************/
  360. void Test_textmode(void)
  361. {
  362.    int rc,i;
  363.    rc=Textmode(25);
  364.    printf("Textmode(25)=%u. (80x25)\n", rc);
  365.    for (i=2; i<25; i++) {
  366.        if (kbhit()) break;
  367.        printf("%2u %s%s\r\n", i, teststring1, teststring2);
  368.    }
  369.    pause();
  370.  
  371.    printf("Doing Textmode(28).");
  372.    pause();
  373.    rc=Textmode(28);
  374.    printf("  Textmode(28)=%u.\n",rc);
  375.    for (i=2; i<28; i++) {
  376.        if (kbhit()) break;
  377.        printf("%2u %s%s\r\n", i, teststring1, teststring2);
  378.    }
  379.    pause();
  380.  
  381.    printf("Doing Textmode(33).");
  382.    pause();
  383.    rc=Textmode(33);
  384.    printf("  Textmode(33)=%u.\n",rc);
  385.    for (i=2; i<33; i++) {
  386.        if (kbhit()) break;
  387.        printf("%2u %s%s\r\n", i, teststring1, teststring2);
  388.    }
  389.    pause();
  390.  
  391.    printf("Doing Textmode(40).");
  392.    pause();
  393.    rc=Textmode(40);
  394.    printf("  Textmode(40)=%u.\n",rc);
  395.    for (i=2; i<40; i++) {
  396.        if (kbhit()) break;
  397.        printf("%2u %s%s\r\n", i, teststring1, teststring2);
  398.    }
  399.    pause();
  400.  
  401.    printf("Doing Textmode(50).");
  402.    pause();
  403.    rc=Textmode(50);
  404.    printf("  Textmode(50)=%u.\n",rc);
  405.    for (i=2; i<50; i++) {
  406.        if (kbhit()) break;
  407.        printf("%2u %s%s\r\n", i, teststring1, teststring2);
  408.    }
  409.    pause();
  410. }
  411.  
  412. /*****************************************************/
  413. /*   VESA modes                                      */
  414. /*****************************************************/
  415. void Test_vesax100(void)
  416. {
  417.    int rc, i, t;
  418.  
  419.    rc=isVESA();
  420.    if ( rc == 0 ) {
  421.        printf("\nSorry, VESA BIOS not found.\n");
  422.        pause();
  423.        return;
  424.    }
  425.    printf("Doing VESAmode(0x100,NULL).\n");
  426.    pause();
  427.    rc=VESAmode(0x100,NULL);
  428.    Vborder_color(0);
  429.    sprintf(temps,"VESAmode(0x100,NULL)=%u. (640x400 in 256 colors)\r\n",rc);
  430.    _foreground_color=0x41; Vputs(temps);
  431.    t=Vnext_break_row;
  432.    sprintf(temps,"Page 0: next page break= scan line %u\r\n",t);
  433.    _foreground_color=0x42; Vputs(temps);
  434.    VESAsetpage(1);
  435.    t=Vnext_break_row;
  436.    sprintf(temps,"Page 1: next page break= scan line %u\r\n",t);
  437.    _foreground_color=0x43; Vputs(temps);
  438.    VESAsetpage(2);
  439.    t=Vnext_break_row;
  440.    sprintf(temps,"Page 2: next page break= scan line %u\r\n",t);
  441.    _foreground_color=0x43; Vputs(temps);
  442.    VESAsetpage(3);
  443.    t=Vnext_break_row;
  444.    sprintf(temps,"Page 3: next page break= scan line %u\r\n",t);
  445.    _foreground_color=0x44; Vputs(temps);
  446.    _foreground_color=0x50;
  447.    for (i=6; i<22; i++) {
  448.        sprintf(temps,"%2u %s%s\r\n", i, teststring1, teststring2);
  449.        Vputs(temps); _foreground_color++;
  450.    }
  451.    pause();
  452.    _foreground_color=0x60; Vputs("Doing VESAcopy256(...)\r\n");
  453.    pause();
  454.    rc=VESAcopy256(350, 150, 10, 50, 240, 200);
  455.    pause();
  456.    sprintf(temps,"VESAcopy256(...)=%u\r\n",rc);
  457.    _foreground_color=0x61; Vputs(temps);
  458.    pause();
  459.    _foreground_color=0x62;
  460.    Vputs("Note that the putstty BIOS function doesn't support scrolling"
  461.          " in VESA modes.\r");
  462.    pause();
  463.    VESAcopy256(0, 0, 0, 16, 640, 384);
  464.    VESAfill256(0, 384, 640, 16, 255);
  465.    _foreground_color=0x63; Vputs("But we can fake it.\r");
  466.    pause();
  467.    VESAcopy256(0, 0, 0, 16, 640, 384);
  468.    VESAfill256(0, 384, 640, 16, 255);
  469.    _foreground_color=0x64; Vputs(" (if a bit slowly)\r");
  470.    pause();
  471.    VESAcopy256(0, 0, 0, 16, 640, 384);
  472.    VESAfill256(0, 384, 640, 16, 255);
  473.    pause();
  474. }
  475.  
  476.